#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e5+10;
const ll inf = 0x3f3f3f3f3f3f3f3f;

int rt,ch[N][2],sz[N],n,nodenum,stk[N],top,fa[N];
ll A[N],B[N],v[N];

void pushup(int u){sz[u] = sz[ch[u][0]] + sz[ch[u][1]] + 1;}
void add(int u,ll a,ll b){A[u] += a;B[u] += b;v[u] += (sz[ch[u][0]] + 1) * a + b;}
void pushdown(int x){
	if(A[x] || B[x]){
		if(ch[x][0]) add(ch[x][0],A[x],B[x]);
		if(ch[x][1]) add(ch[x][1],A[x],B[x] + (sz[ch[x][0]] + 1) * A[x]);
		A[x] = B[x] = 0;
	}
}
void Rotate(int x){
	int y = fa[x],z = fa[y],k = ch[y][1] == x;
//	cerr<<x<<".."<<y<<".."<<z<<endl;
	fa[x] = z; if(z) ch[z][ch[z][1] == y] = x;
	ch[y][k] = ch[x][k ^ 1]; fa[ch[x][k ^ 1]] = y;
	ch[x][k ^ 1] = y; fa[y] = x; pushup(y); pushup(x);
}

void Splay(int x){
	stk[top = 1] = x; for(int i = x;fa[i];i = fa[i]) stk[++top] = fa[i];
	while(top) pushdown(stk[top--]);
	while(fa[x]){
		int y = fa[x],z = fa[y];//cerr<<"!"<<y<<".."<<z<<endl;
		if(z) (ch[z][0] == y) ^ (ch[y][0] == x) ? Rotate(x) : Rotate(y);
		Rotate(x);
	}rt = x;
}

ll getval(int x){
	int u = rt; 
	while(1){
//		cerr<<x<<".."<<sz[u] << ".."<<sz[ch[u][0]]<<endl;
		if(sz[ch[u][0]] + 1 == x) {Splay(u); return v[u];}
		else if(sz[ch[u][0]] >= x) u = ch[u][0];
		else x -= sz[ch[u][0]] + 1,u = ch[u][1];
	}
}

ll getmax(int x){
	if(!x) return -inf;pushdown(x);
	return max(getmax(ch[x][0]),max(getmax(ch[x][1]),v[x]));
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;
	rt = nodenum = sz[1] = 1;
	for(int i = 1;i <= n;i++){
		ll x = in;
		int l = 0,r = i - 2,ps = i - 1;
		while(l <= r){
			int mid = l + r >> 1;
			if(getval(mid + 1) + (mid + 1) * x > getval(mid + 2)) r = mid - 1,ps = mid;
			else l = mid + 1;
		}getval(ps+1);
		++nodenum; fa[nodenum] = rt; v[nodenum] = v[rt]; ch[nodenum][1] = ch[rt][1]; fa[ch[rt][1]] = nodenum; ch[rt][1] = nodenum; 
		add(nodenum,x,x * ps); Splay(nodenum);
	}
	printf("%lld\n",getmax(rt));
	return 0;
}

